
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Swaf.Gui;
/// <summary>
/// Summary description for ActionButton
/// </summary>
/// 
namespace Syrinx.Gui.AspNet
{
    [ToolboxData("<{0}:SimpleActionButton runat=server></{0}:SimpleActionButton>")]
	public class SimpleActionButton : Button
	{
		protected IAction m_action;

		protected bool m_hideOnDisabled = true;
        public SimpleActionButton()
		{
			this.Click += new EventHandler(ActionButton_Click);
		}
		public bool HideOnDisabled
		{
			get { return m_hideOnDisabled; }
			set { m_hideOnDisabled = value; }
		}

		void ActionButton_Click(object sender, EventArgs e)
		{
			if (m_action != null)
				m_action.trigger();
		}

		public IAction Action
		{
			get { return m_action; }
			set {
				m_action = value;
				m_action.ActionChanged += new ActionChanged(m_action_ActionChanged);
				this.Enabled = m_action.Enabled;

				if (!this.Enabled)
					this.Visible = !m_hideOnDisabled;
				else
					this.Visible = true;
			}
		}

		void m_action_ActionChanged(object sender, ActionChangeType type)
		{
			this.Enabled = m_action.Enabled;

			if (!this.Enabled)
				this.Visible = !m_hideOnDisabled;
			else
				this.Visible = true;

		}
	}
}
